package com.park.microprofile.configsource;

import org.eclipse.microprofile.config.spi.ConfigSource;

import java.util.*;

/**
 * Java 系统属性配置源
 *
 * @author Aaron
 * @date 2021/7/13 9:30
 */
public class DefaultJavaSystemPropertiesSource implements ConfigSource {

    /**
     * Java 系统属性配置
     */
    private final Map<String, String> systemProperties = new HashMap<>();

    /**
     * 配置源的优先级
     */
    int ordinal = 400;

    public DefaultJavaSystemPropertiesSource() {
        Properties properties = System.getProperties();
        properties.forEach((k, v) -> systemProperties.put(k.toString(), v.toString()));
    }


    @Override
    public Set<String> getPropertyNames() {
        return Collections.unmodifiableSet(systemProperties.keySet());
    }

    @Override
    public String getValue(String propertyName) {
        return systemProperties.get(propertyName);
    }

    @Override
    public String getName() {
        return "Java System Config Source";
    }


}
